package com.lk.api.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lk.api.R;
import com.lk.api.entity.Users;

/**
 * Created by lk on 2014/12/26.
 */
public class Upd extends Activity {
    EditText editTextName, editTextPwd;
    Intent intent;
    DBOperation dbOperation;
    Button button;
    Users users;
    String[] array;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.u);
        editTextName = (EditText) findViewById(R.id.editNameUpd);
        editTextPwd = (EditText) findViewById(R.id.editPwdUpd);

        dbOperation = new DBOperation(Upd.this);
        dbOperation.openOrCreateDatabase();

        Bundle b = this.getIntent().getExtras();
        array = b.getStringArray("Upd_id");
//        Log.d("id:", "" + array[0]);
//        Log.d("names:", "" + array[1]);
//        Log.d("pwd:", "" + array[2]);


        users = new Users();
        editTextName.setText("" + array[1]);
        editTextPwd.setText("" + array[2]);


        button = (Button) findViewById(R.id.buttonUpd);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (users != null && dbOperation != null) {
                    users.setNames(editTextName.getText().toString());
                    users.setPwd(editTextPwd.getText().toString());
                    dbOperation.updateData(users, Integer.valueOf(array[0]));
                    Toast.makeText(Upd.this, "保存成功", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(Upd.this, "保存失败", Toast.LENGTH_LONG).show();
                }
                finish();

            }
        });

    }

}
